package cn.edu.wfit.modules.learn.controller.competitionmanagement;

import java.util.List;

import cn.edu.wfit.modules.learn.domain.WfitCompetitionTeamregistration;
import cn.edu.wfit.modules.learn.domain.dto.TeamDetailDto;
import cn.edu.wfit.modules.learn.service.competitionmanagement.IWfitCompetitionTeamregistrationService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 团队赛队伍报名Controller
 * 
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/teamregistration")
public class WfitCompetitionTeamregistrationController extends BaseController
{
    @Autowired
    private IWfitCompetitionTeamregistrationService wfitCompetitionTeamregistrationService;

    /**
     * 查询团队赛队伍报名列表
     */
    @RequiresPermissions("system:teamregistration:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitCompetitionTeamregistration wfitCompetitionTeamregistration)
    {
        startPage();
        List<WfitCompetitionTeamregistration> list = wfitCompetitionTeamregistrationService.selectWfitCompetitionTeamregistrationList(wfitCompetitionTeamregistration);
        return getDataTable(list);
    }

    /**
     * 导出团队赛队伍报名列表
     */
    @RequiresPermissions("system:teamregistration:export")
    @Log(title = "团队赛队伍报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitCompetitionTeamregistration wfitCompetitionTeamregistration)
    {
        List<WfitCompetitionTeamregistration> list = wfitCompetitionTeamregistrationService.selectWfitCompetitionTeamregistrationList(wfitCompetitionTeamregistration);
        ExcelUtil<WfitCompetitionTeamregistration> util = new ExcelUtil<WfitCompetitionTeamregistration>(WfitCompetitionTeamregistration.class);
        util.exportExcel(response, list, "团队赛队伍报名数据");
    }

    /**
     * 获取团队赛队伍报名详细信息
     */
    @RequiresPermissions("system:teamregistration:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitCompetitionTeamregistrationService.selectWfitCompetitionTeamregistrationById(id));
    }

    /**
     * 新增团队赛队伍报名
     */
    @RequiresPermissions("system:teamregistration:add")
    @Log(title = "团队赛队伍报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitCompetitionTeamregistration wfitCompetitionTeamregistration)
    {
        return toAjax(wfitCompetitionTeamregistrationService.insertWfitCompetitionTeamregistration(wfitCompetitionTeamregistration));
    }

    /**
     * 修改团队赛队伍报名
     */
    @RequiresPermissions("system:teamregistration:edit")
    @Log(title = "团队赛队伍报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitCompetitionTeamregistration wfitCompetitionTeamregistration)
    {
        return toAjax(wfitCompetitionTeamregistrationService.updateWfitCompetitionTeamregistration(wfitCompetitionTeamregistration));
    }

    /**
     * 删除团队赛队伍报名
     */
    @RequiresPermissions("system:teamregistration:remove")
    @Log(title = "团队赛队伍报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitCompetitionTeamregistrationService.deleteWfitCompetitionTeamregistrationByIds(ids));
    }

    /**
     * 根据学号查询团队赛队伍报名列表
     * @param studentId
     * @return
     */
    @GetMapping("/TeamListByStudentId/{studentId}")
    public AjaxResult TeamListByStudentId(@PathVariable("studentId") String studentId)
    {
        List<TeamDetailDto> list = wfitCompetitionTeamregistrationService.TeamListByStudentId(studentId);
        return success(list);
    }

    /**
     * 根据 学号 查询队伍成员关联表
     * @param studentId
     * @return
     */
    @GetMapping("/TeamMemberListByStudentId/{studentId}")
    public AjaxResult TeamMemberListByStudentId(@PathVariable("studentId") String studentId)
    {
        List<TeamDetailDto> list = wfitCompetitionTeamregistrationService.TeamMemberListByStudentId(studentId);
        return success(list);
    }


}
